{extend name="base" /}
{block name="content"}
<script src="__STATIC__/public/My97DatePicker/WdatePicker.js"></script>
<div class="g-main">
    <div class="m-main-title">
        <div class="m-container-fluid">
            <a href="{:url('index/welcome')}">
                <i class="icon icon-home"></i>首页</a>
            <span class="icon-angle-right"></span>
            <span>商城</span>
            <span class="icon-angle-right"></span>
            <span>角色价格</span>
            <span class="icon-angle-right"></span>
            <span>设置角色价格</span>
            <a class="u-flush">
                <i class="icon-repeat"></i>
            </a>
        </div>
    </div>
    <div class="m-main-content">
        <div class="m-container">

            <table class="m-table">
                <tbody>
                <tr>
                    <td width="15%"><label for="">商品名称</label></td>
                    <td>{$info.goods_name}</td>
                </tr>

                <tr>
                    <td width="15%"><label for="">商品价格</label></td>
                    <td>{$info.sale_price}</td>
                </tr>


            </table>
            <form class="layui-form" id="j_form" style="padding-top: 20px;">
                <table class="m-table ">
                    <tbody>
                        <tr>
                            <th width="5%">ID</th>
                            <th width="10%">角色名称</th>
                            <th width="10%">会员价格</th>
                            <th width="10%">操作</th>
                        </tr>

                        {foreach name="mr_list" item="v"}
                        <tr>
                            <td>{$v.id}</td>
                            <td>{$v.name}</td>
                            <td><input type="text" class="u-ipt u-ipt-small sale_price" data-id="{$v.id}" name="sale_price"  placeholder="请输入活动价格" value="{$v.sale_price|default=0}" />元,<span style="color:#CCCCCC;">未设置价格，默认商品正常价格</span></td>
                            <td class="m-opt">
                                <a href="javascript:;" class="s_btn" data-id="{$v.id}" title="">设置规格价格</a>
                            </td>
                        </tr>
                        {/foreach}
                    </tbody>
                </table>

            </form>
        </div>
    </div>
</div>
{/block}{block name="extrajs"}

<script>
    $(function(){
        layui.use('layer', function(){

            $('.sale_price').on('change',function () {
                var id =$(this).attr('data-id');//角色id
                var sale_price=$(this).val();//价格
                var goods_id="{$info.id}";

                $.post('/manage/role_goods/setPrice',{role_id:id,sale_price:sale_price,goods_id:goods_id},function (res) {
                    if(res.code===1){
                        layer.msg(res.msg)
                    }else{
                        layer.msg(res.msg)
                    }
                })
            })
        });

        $('.s_btn').on('click', function () {
            var goods_id="{$info.id}";
            var role_id =$(this).attr('data-id');//角色id

            layer.open({
                type: 2,
                title: '规格价格',
                shadeClose: false,
                shade: 0,
                area: ['80%', '70%'],
                content: '/manage/role_goods/addsku?goods_id='+goods_id+"&role_id="+role_id//iframe的url
            });
        });
    })
</script>
{/block}